﻿package{
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	import flash.net.URLLoader;
	import flash.net.URLRequestMethod;
	import flash.net.URLLoaderDataFormat;
	import flash.net.navigateToURL;
	import flash.events.NetStatusEvent;
	import flash.net.URLVariables;

	public class documentClass extends MovieClip{
/*		var restart:Restart=new Restart();*/
		var egg1:Egg1=new Egg1();
		var egg2:Egg2=new Egg2();
		var win:Win=new Win();
		var flag:Boolean=false;
		var lose:Lose=new Lose();
		var fi:int=0;
		var lucky:int=0;
		var winpt:int=0;
		var losept:int=0;
		public function documentClass(){
			lucky=Math.floor(Math.random()*2)+1;
			/*restart.x=460;
			restart.y=370;*/
			egg1.x=265;
			egg1.y=220;
			egg2.x=435;
			egg2.y=220;
			win.x=330;
			win.y=150;
			lose.x=330;
			lose.y=150;
			//addChild(restart);
			addChild(egg1);
			addChild(egg2);
			trace (lucky);
			egg1.addEventListener(MouseEvent.CLICK,egg1click);
			egg2.addEventListener(MouseEvent.CLICK,egg2click);

		}
			
			private function egg1click(event:MouseEvent)
			{
				flag=true;
				removeChild(egg1);
				removeChild(egg2);
				if(lucky==1)
				{
					addChild(win);
					fi=1;
					winpt=1;
				}
				else
				{
					addChild(lose);
					fi=2;
					losept=1;
				}
				update_db();
			}
			private function egg2click(event:MouseEvent)
			{
				flag=true;
				removeChild(egg1);
				removeChild(egg2);
				if(lucky==2)
				{
					addChild(win);
					fi=1;
					winpt=1;
				}
				else
				{
					addChild(lose);
					fi=2;
					losept=1;
				}
				update_db();
				
			}
			
			private function update_db()
			{
				var req:URLRequest = new URLRequest ("test.php");
				req.method = URLRequestMethod.POST;
				var variables:URLVariables = new URLVariables();
				variables.gameid=2;
				variables.win=winpt;
				variables.lose=losept;
				req.data = variables;         
				var loader:URLLoader = new URLLoader (req);
				loader.dataFormat = URLLoaderDataFormat.TEXT;
				loader.load(req);
				navigateToURL(new URLRequest("main.php"),'_self');
			}
		
	}
	
}